package com.alg.test;

/**
 * @author Li
 * @Date 2023/4/19 15:08
 */
public class MyStringBuilder {
    public static void main(String[] args) {
        StringBuilder ws = new StringBuilder();
  //        append 进行任意类型，字符串拼接
        ws.append("hello").append("world").append(520);
        System.out.println(ws);
        ws.reverse();
        //reverse() 字符序列反转
        System.out.println(ws);

//        打印数组
        int[] array = {1,2,3,4};
        print(array);
    }

    /**
     * append字符串拼接数组
     * @param array
     */
    private static void print(int[] array) {
        StringBuilder arr = new StringBuilder();
        arr.append("[");
        for (int i = 0; i <array.length ; i++) {
            if (i==array.length-1){
                arr.append(array[i]).append("]");
            }else {
                arr.append(array[i]).append(",");
            }
        }
        System.out.println(arr);
    }

}
